﻿#include "FITKAcousticsVTKGraphObjectSEAJunctionArea.h"

// VTK
#include <vtkProperty.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPoints.h>

// App
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"

// Data
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscNodeList.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEAJunctionArea.h"

// Graph and filter
#include "FITKAcousticsVTKCommons.h"
#include "FITKAcousticsVTKSharedDataManager.h"
#include "FITKAcousticsVTKGraphObjectSelect.h"
#include "FITK_Interface/FITKVTKAlgorithm/FITKGraphActor.h"

namespace Exchange
{
    FITKAcousticsVTKGraphObjectSEAJunctionArea::FITKAcousticsVTKGraphObjectSEAJunctionArea(Acoustics::FITKSEAJunctionArea* jArea)
        : FITKAcousticsVTKGraphObjectSEAJunction(jArea)
    {
        // Return if the input is nullptr.
        if (!jArea)
        {
            return;
        }

        // Intiailize the polygon offset.
        m_polygonOffset = FITKAcousticsVTKCommons::s_polygonOffsetSEAJunction;

        // Initialize the vtk object.
        init();

        // Generate the data set.
        if (!generateDataSet(jArea))
        {
            return;
        }

        // Generate the nodes actor.
        generateGraph();

        // Update the visibility.
        updateVisibility();

        // Save the data type.
        m_graphInfo.Type = FITKAcousticsVTKCommons::JunctionArea;
    }

    void FITKAcousticsVTKGraphObjectSEAJunctionArea::updateVisibility()
    {
        // Get the runtime settings for visibility.
        bool showJunc = getGlobalSEAJunctionsVisibility();
        bool showJAreas = getRuntimeSettingAs<bool>(RTS_KEY_VISIBLE_JUNCTION_AREAS, true);
        bool showSEAJAreas = getRuntimeSettingAs<bool>(RTS_KEY_VISIBLE_SEA_JUNC_AREAS, true);
        bool mainFlag = this->Superclass::getDataVisibility() && showJunc && showJAreas && showSEAJAreas;

        // Update the visibility with the flags.
        //@{
        // Show or hide actors.
        setVisible(mainFlag);
        //@}
    }

    bool FITKAcousticsVTKGraphObjectSEAJunctionArea::generateDataSet(Acoustics::FITKAbstractJunction* junction)
    {
        if (!m_points || !m_ugrid)
        {
            return false;
        }

        Acoustics::FITKSEAJunctionArea* jArea = dynamic_cast<Acoustics::FITKSEAJunctionArea*>(junction);
        if (!jArea)
        {
            return false;
        }

        // Get the SEA node list.
        Acoustics::FITKAcousticsDiscNodeList* seaNodes = getSEANodesData();
        if (!seaNodes)
        {
            return false;
        }

        return true;
    }
}   // namespace Exchange